#ifndef RATIONAL_H
#define RATIONAL_H

struct Rational {
	Rational();
	Rational(int);
	Rational(int, int);
	Rational(const Rational&);
	Rational& operator=(const Rational&);

	friend Rational operator+(const Rational&, const Rational&);
	friend Rational operator-(const Rational&, const Rational&);
	friend Rational operator*(const Rational&, const Rational&);
	friend Rational operator/(const Rational&, const Rational&);

	Rational& operator+=(const Rational&);
	Rational& operator-=(const Rational&);
	Rational& operator*=(const Rational&);
	Rational& operator/=(const Rational&);
	Rational operator+() const;
	Rational operator-() const;
	Rational& operator++();
	Rational operator++(int);
	Rational& operator--();
	Rational operator--(int);

	friend bool operator==(const Rational&, const Rational&);
	friend bool operator!=(const Rational&, const Rational&);
	friend bool operator<(const Rational&, const Rational&);
	friend bool operator<=(const Rational&, const Rational&);
	friend bool operator>(const Rational&, const Rational&);
	friend bool operator>=(const Rational&, const Rational&);

private:
	int gcd(int, int);
	void simplify();
	void swap(Rational&);

	int p;
	int q;
};

Rational operator+(const Rational&, const Rational&);
Rational operator-(const Rational&, const Rational&);
Rational operator*(const Rational&, const Rational&);
Rational operator/(const Rational&, const Rational&);
bool operator==(const Rational&, const Rational&);
bool operator!=(const Rational&, const Rational&);
bool operator<(const Rational&, const Rational&);
bool operator<=(const Rational&, const Rational&);
bool operator>(const Rational&, const Rational&);
bool operator>=(const Rational&, const Rational&);

#endif
